package com.pk.springbootsy1.commen;

import cn.dev33.satoken.stp.StpInterface;
import com.pk.springbootsy1.entity.TUser;
import com.pk.springbootsy1.enums.RoleEnum;
import com.pk.springbootsy1.service.TUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class StpInterfaceImpl implements StpInterface {

    @Autowired
    private TUserService userService;
    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return null;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        List<String> Roles = new ArrayList<>();
        TUser user = userService.getById(Integer.parseInt((String) loginId));
        Integer type = user.getType();
        if (RoleEnum.ADMIN.getCode().equals(type)) {
            Roles.add(RoleEnum.ADMIN.getMessage());
        }
        else if (RoleEnum.USER.getCode().equals(type)) {
            Roles.add(RoleEnum.USER.getMessage());
        }
        return Roles;
    }



}
